﻿using UnityEngine;
using System.Collections;
using FairyGUI;

/// <summary>
/// 游戏窗口
/// </summary>
public class UIGameWindow : UIBaseWindow {

    UIGame_WaitingCtrl _waitingCtrl;
    UIGame_TalkCtrl _talkCtrl;
    UIGame_Player[] _playerCtrls;
    GTextField _roomIdCtrl;

	public UIGameWindow()
    {
        // 初始化界面
        UIPackage.AddPackage("UI/游戏界面");

        base.Init(UIPackage.CreateObject("游戏界面", "游戏界面").asCom);

        _roomIdCtrl = uiComp.GetChild("房间号").asTextField;

        _waitingCtrl = new UIGame_WaitingCtrl(uiComp.GetChild("等待按钮组").asCom);
        _talkCtrl = new UIGame_TalkCtrl(uiComp.GetChild("聊天组件").asCom);

        _playerCtrls = new UIGame_Player[3];
        _playerCtrls[0] = new UIGame_Player(uiComp.GetChild("我方玩家").asCom, true);
        _playerCtrls[1] = new UIGame_Player(uiComp.GetChild("左上玩家").asCom);
        _playerCtrls[2] = new UIGame_Player(uiComp.GetChild("右上玩家").asCom);

        GameDataKernel.inst.gameWin = this;
        GameDataKernel.inst.InitPlayers(3, _playerCtrls);
    }

    public override void OnExit()
    {
        uiComp.Dispose();
        UIPackage.RemovePackage("UI/游戏界面");
    }

    public void SetRoomId(int roomId)
    {
        _roomIdCtrl.text = "房间号：" + roomId;
    }

    public bool waitingCtrlVisible {
        get { return _waitingCtrl.visible; }
        set { _waitingCtrl.visible = value; }
    }
}
